input=$1
if [ $# -eq 0 ]
  then
    echo "No arguments supplied"
    echo "Please provide path of host port list"
    exit 1
fi
while read -r line || [ -n "$line" ];
do
  host=$(echo $line | cut -f1 -d " ")
  port=$(echo $line | cut -f2 -d " ")
  echo -e '\x1dcclose\x0d' | telnet $host $port && echo "${host}:${port} is open" | \
  tee -a ./$(hostname)-open.output
done < "$input" 2>>$(hostname)-closed.output